<?php
namespace Pc\Controller;
use Think\Controller;
/**
 * 子集详细列表页控制器 ListController.class.php
 */
class ListController extends CommonController{
    /* 属性声明 */
    //扩展配置文件
    private $kz_conf_file = "./Org/Data/kz_conf.json";
    //时间验证字段配置文件
    private $sj_conf_file = "./Org/Data/sj_zd_conf.json";
    /* 方法声明 */
    /**
     * 构造方法
     */
    public function __construct() {
        parent::__construct();
        //检测用户合法性
        if(!$this -> uuid = session('uuid')){
            $this -> error('获取员工标识失败!');
        }

        $data = I('get.');
        //获取菜单项
        if(!$this -> menu = $data['menu']){
            $this -> error('非法参数传递!');
        }
    }

    /**
     * 入口方法
     */
    public function index(){
        //1.获取常规字典数据
        $this -> createDic();
        //2.获取已经提交审核的子集项
        $this -> redis -> select(11);
        if($change_item = $this->redis->hvals('items_'.$this->uuid)){
            $str = '';
            foreach($change_item as $k=>$v){
                $v = unserialize($v);
                $str .= implode(',',$v).',';
            }
            $change_item = rtrim($str,',');
        }else{
            $change_item = '';
        }
        //dump($change_item);exit;
        //3.成员数据
        $userinfo = $this ->getUserInfo($this -> uuid);

        //4.获取子集数据
        $dat = $this -> getSublist($userinfo,$this->menu);
        if(!$dat){
            $this -> error('未知menu数据!');
            exit;
        }
        //dump($dat);exit;
        //5.是否可拓展标记 单值 多值
        $is_extension = $this -> menu == 'BO_CASC_HR_YGRS' ? 0 : 1;

        //6.获取扩展配置文件
        $kz_info = json_decode(file_get_contents($this->kz_conf_file),true);
        $kz_info = $kz_info[$this->menu];
        //dump($kz_info);exit;

        //7.获取时间验证字段
        $sj_info = json_decode(file_get_contents($this->sj_conf_file),true);
        $sj_info = $sj_info[$this->menu];
        //dump($sj_info);exit;

        //8.获取type为file字段
        $file_zd = [];
        foreach($dat['sublist'] as $k=>$v){
            if($v['type'] =='FILE'){
                $file_zd[] = $k;
            }
        }
        //9 .获取附件信息
        if($file_zd){
            $dat = $this->getFileInfo($this->uuid,$this->menu,$file_zd,$dat);
        }
        //dump($dat);exit;
        //获取图片的URL
        if($this->menu == 'BO_CASC_HR_YGRS'){
            $zp_key = array_keys($dat['sublist']['ZP']['value']);
            $zp_img = $dat['sublist']['ZP']['value'][$zp_key[0]]['href'];
            $this->assign('zp_img',$zp_img);
        }

        $this -> assign([
            'uuid'         => $this->uuid,
            'is_extension' => $is_extension,
            'menu'         => $this->menu,
            'caption'      => $dat['caption'],
            'info'         => json_encode($dat),
            'kz_info'      => json_encode($kz_info),
            'dic'          => $this -> dic,
            'layer'        => $this -> layer,
            'change_item'  => $change_item,
            'sj_info'      => json_encode($sj_info),
        ]);
        $this -> display('list');
    }




}
